<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>发运单列表</title>
<link href="/resources/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<link href="/resources/lib/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
<script src="/resources/lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="/resources/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>
<script src="/resources/lib/ligerUI/js/ex/ligerGrid.showFilter.js" type="text/javascript"></script>
<script src="/resources/lib/ligerUI/js/ex/ligerFilterEx.js" type="text/javascript"></script>
<script src="/resources/js/jsF7.js" type="text/javascript"></script>
<script src="/resources/js/selectData.js" type="text/javascript"></script>
<script src="/resources/js/validation.js" type="text/javascript"></script>

<script type="text/javascript">
        var $grid;
        var form;
        $(function (){
            //创建表格对象 高级查询editor 识别编辑器有：combobox date number string
            $grid = $("#maingrid").ligerGrid({
                columns: [
                { name: 'uuid', hide:true,type:"text"},
                /* { display: '单据编号', name: 'number', width: 140,type:"text"},
                { display: '状态', name: 'status', width: 100,type:"text"}, */
                { display: "单据编号 ", name: "number", type: "text",minWidth:100 },
	            { display: "部门", name: "depGroup.uuid", minWidth:100, type: "popup",textField:'depGroup.name',
	            	 editor: {type: "popup",
	                    grid: getDepGroupGrid(true),
	                    valueField:'uuid',
	                    textField: 'name',
	                    parms :{date:new Date().getTime()},
	                    realTimeLoad:true
	           	 }
	           },
				{ display: "发运日期", name: "bizDate", type: "date",minWidth:100, editor:{type:'date'}},
	            { display: "主承运方", name: "shipper.uuid", type: 'popup',minWidth:100,textField:'shipper.name',
	             	 editor: {type: "popup",
	                      grid: getMainResponsibleTransportCoGrid(true),
	                      valueField:'uuid',
	                      textField: 'name',
	                      parms :{date:new Date().getTime()},
	                      realTimeLoad:true/* ,
	                      onSelected:function(e){
	                    	  var edd = form2.getEditor("createUser.uuid"); //form中应用
	                    	  edd.setText(e.text);
	                    	  console.log(e);
	                      } */
	             	 }
	             },
				{ display: "运输方式", name: "transitWay.uuid", type: 'popup',minWidth:100,textField:'transitWay.name',
	             	 editor: {type: "popup",
	                      grid: getTransportModeGrid(true),
	                      valueField:'uuid',
	                      textField: 'name',
	                      parms :{date:new Date().getTime()},
	                      realTimeLoad:true/* ,
	                      onSelected:function(e){
	                    	  var edd = form2.getEditor("createUser.uuid"); //form中应用
	                    	  edd.setText(e.text);
	                    	  console.log(e);
	                      } */
	             	 }
	             },
				
				{ display: "车辆	", name: "car", minWidth:100,type: "text"},
				{ display: "司机	", name: "driver", minWidth:100,type: "text"},
				{ display: "费用金额", name: "taxAmount", minWidth:100, type: "float",editor:{type:"float"}},
				{ display: "备注", name: "remark", minWidth:100, type: "text", minWidth: 170},
				{ display: "创建人", name: "createUser.uuid", type: 'popup',minWidth:100,textField: 'createUser.trueName',
	            	 editor: {type: "popup",
	                     grid: getSysUserGrid(true),
	                     valueField:'uuid',
	                     textField: 'trueName',
	                     parms :{date:new Date().getTime()},
	                     realTimeLoad:true
	            	 }
	            },
	            { display: "创建日期", name: "createDate", minWidth:100, type: "date",editor:{type:'date'}},
	            { display: "单据状态", name: "status", minWidth:100, type: "select",
	            	 render: function(item)
	                   {
	            		   var re = null;
	                      switch (item.status){
	                       case "1":
	                    	   re = "新增";
	                    	break;
	                       case "2":
	                    	   re = "保存";
	                    	break;
	                       case "3":
	                    	   re = "提交";
	                    	break;
	                       case "4":
	                    	   re = "审核";
	                    	break;
	                      }
	                      return re;
	                   } ,editor: {type:'combobox',options:{data:getStatsSelect()}} }
                ],
                autoFilter:true,
                width: '100%', pageSizeOptions: [5, 10, 15, 20], height: '100%',
                checkbox: true,headerRowHeight:22, rowHeight:22, rownumbers:true,
                url:'/dispatch/listData',
                onLoadData:onloadData,
                onDblClickRow:onDblClickRow,
                toolbar: { items: [
                                   { text: '新增', click: addClick, icon: 'add' },
                                   { line: true },
                                   { text: '修改', click: alertClick, icon: 'modify' },
                                   { line: true },
                                   { text: '删除', click: delClick, icon: 'delete' },
/*                                    { line: true },
                                   { text: '提交', click: submitClick},
                                   { line: true },
                                   { text: '审核', click: auditClick},
                                   { line: true },
                                   { text: '反审核', click: unAuditClick}, */
                                   ]
                                   }
            });

        });
        //添加
        function addClick(item){
        	f_addTab('addDispatch','新增库发运单','/dispatch/addDispatch');
        }
        //双击事件(查看)
        function onDblClickRow(data, rowindex, rowobj){
        	f_addTab('viewDispatch','查看库发运单','/dispatch/viewDispatch?uuid='+data.uuid);

        }
        
        //删除
        function delClick(){
        	var rows = $grid.getSelectedRows();
        	if(rows == null || rows.length < 1){
        		$.ligerDialog.error("请至少选择一行数据");
        		return;
        	}
        	if(delBatchvalidation(rows)){
  			   $.ligerDialog.error("只有保存或提交状态的数据才能删除");
  			   return;
         	}
        	var uuids = new Array();
        	for(var i=0;i<rows.length;i++){
        		uuids[i] = rows[i].uuid; 
        	}
    		$.ajax({ 
    			url: '/dispatch/delDispatch', 
    			data:{rows : JSON.stringify(uuids)}, 
    			type: "post", 
    			dataType:'json',
    			cache : false, 
    			success: function(data){
    				$.ligerDialog.success(data.message,'信息',function(){
    		        	 $grid.reload();
    				});
    			},
    	        error: function (message) {
    	            $.ligerDialog.error("删除失败");
    	        }
    	});
        }
        //修改
        function alertClick(){
        	var rows = $grid.getSelectedRows();
        	if(rows == null || rows.length < 1 || rows.length != 1){
        		$.ligerDialog.error("请选择一条要修改的数据");
        		return;
        	}
        	f_addTab('alterDispatch','修改库发运单','/dispatch/alterDispatch?uuid='+rows[0].uuid);
        }
        
        //提交
        function submitClick(){
        	var rows = $grid.getSelectedRows();
        	if(rows == null || rows.length < 1){
        		$.ligerDialog.error("请至少选择一行数据");
        		return;
        	}
    		$.ajax({ 
    			url: '/dispatch/submitDispatch', 
    			data:{rows : JSON.stringify(rows)}, 
    			type: "post", 
    			dataType:'json',
    			cache : false, 
    			success: function(data){
    				$.ligerDialog.success(data.message,'信息',function(){
    		        	 $grid.reload();
    				});
    			},
    	        error: function (message) {
    	            $.ligerDialog.error("提交成功");
    	        }
    	});
      	}
        
        //审核
        function auditClick(){
        	var rows = $grid.getSelectedRows();
        	if(rows == null || rows.length < 1){
        		$.ligerDialog.error("请至少选择一行数据");
        		return;
        	}
    		$.ajax({ 
    			url: '/dispatch/auditDispatch', 
    			data:{rows : JSON.stringify(rows)}, 
    			type: "post", 
    			dataType:'json',
    			cache : false, 
    			success: function(data){
    				$.ligerDialog.success(data.message,'信息',function(){
    		        	 $grid.reload();
    				});
    			},
    	        error: function (message) {
    	            $.ligerDialog.error("审核成功");
    	        }
    	});
        }
        
        //反审核
        function unAuditClick(){
        	var rows = $grid.getSelectedRows();
        	if(rows == null || rows.length < 1){
        		$.ligerDialog.error("请至少选择一行数据");
        		return;
        	}
    		$.ajax({ 
    			url: '/dispatch/unAuditDispatch', 
    			data:{rows : JSON.stringify(rows)}, 
    			type: "post", 
    			dataType:'json',
    			cache : false, 
    			success: function(data){
    				$.ligerDialog.success(data.message,'信息',function(){
    		        	 $grid.reload();
    				});
    			},
    	        error: function (message) {
    	            $.ligerDialog.error("反审核成功");
    	        }
    	});
        }
        
        
        //查询
        function viewClick(){
        	//重新加载grid
        	 $grid.reload();
        }
        
      //获取数据前添加过滤条件
      function onloadData(){
    	/*   var cond = JSON.stringify(form.getData());
    	  this.options.parms.cond= cond;
    	  this.options.parms.temp= true; */
    	/*   applay(this.options.parms, [{ name: "cond", value: cond, temp: true }]); */
    	 //this.set('parms', [{ name: "cond", value: cond, temp: true }]);
      }
  	  //添加窗口
      function f_addTab(tabid,text, url){
  		this.parent.f_addTab(tabid,text, url);
      } 
    </script>
</head>
<body  style="padding:10px">
    <div id="maingrid"></div> 
</body>
</html>